//
//  BIZOfflineConsultorView.m
//  biz
//
//  Created by zhangfuwei on 2017/4/19.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZOfflineConsultorView.h"
#import "BIZConsultorListDataModel.h"

//  视图间距
static CGFloat kMargin = 5;
static CGFloat kViewMargin = 15;
static CGFloat kEdgeMargin = 20;

@implementation BIZOfflineConsultorView{
    UIImageView *_headImageView;
    UILabel *_nameLabel; // 姓名
    UILabel *_companyLabel;//  公司
    UILabel *_positionLabel; // 职位
    UILabel *_levelNameLabel;// 级别名称
    
    UIButton    *_rechooseButton; // 重新选择咨询师按钮
}


/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
- (instancetype)init {
    self = [super init];
    if (self) {
        
        [self loadCustomizedSubviews];
    }
    return self;
}

- (void)loadCustomizedSubviews {
    _headImageView = [[UIImageView alloc] init];
    _headImageView.layer.cornerRadius = 5;
    _headImageView.clipsToBounds = YES;
    
    _rechooseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rechooseButton setTitle:@"重选咨询师" forState:UIControlStateNormal];
    _rechooseButton.titleLabel.font = CHINESE_SYSTEM(12);
    [_rechooseButton addTarget:self action:@selector(rechooseBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    _rechooseButton.backgroundColor = HEXCOLOR(0xfb6a2e);
    _rechooseButton.layer.cornerRadius = 15;
    _rechooseButton.clipsToBounds = YES;
    

    
    _nameLabel = [[UILabel alloc] init];
    _positionLabel = [[UILabel alloc] init];
    _companyLabel = [[UILabel alloc] init];
    _levelNameLabel = [[UILabel alloc] init];

    _positionLabel.textAlignment = NSTextAlignmentLeft;
    _companyLabel.textAlignment = NSTextAlignmentLeft;
    
    _nameLabel.font = CHINESE_SYSTEM(15);
    _positionLabel.font = CHINESE_SYSTEM(12);
    _companyLabel.font = CHINESE_SYSTEM(12);
    _levelNameLabel.font = CHINESE_SYSTEM(12);
    
    
    _nameLabel.textColor = HEXCOLOR(0x4c5c6c);
    _positionLabel.textColor = HEXCOLOR(0x010101);
    _levelNameLabel.textColor = HEXCOLOR(0x010101);
    _companyLabel.textColor = HEXCOLOR(0x666666);
    
    
    [self addSubview:_headImageView];
    [self addSubview:_rechooseButton];
    [self addSubview:_nameLabel];
    [self addSubview:_positionLabel];
    [self addSubview:_companyLabel];
    [self addSubview:_levelNameLabel];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _headImageView.frame = CGRectMake(kEdgeMargin, kEdgeMargin, 50, 50);
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_headImageView.mas_right).offset(26);
        make.top.equalTo(_headImageView);
        make.height.equalTo(@(15));
    }];
    
    [_positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_nameLabel);
        make.left.equalTo(_nameLabel.mas_right).offset(kMargin);
        make.height.equalTo(@12);
    }];
    
    
    [_levelNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nameLabel);
        make.top.equalTo(_nameLabel.mas_bottom).offset(kViewMargin);
        make.height.equalTo(@12);
    }];
    
    [_companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_levelNameLabel.mas_bottom).offset(11);
        make.left.equalTo(_nameLabel);
        make.right.equalTo(_rechooseButton.mas_left).offset(kMargin);
        make.height.equalTo(@12);
    }];
    
    [_rechooseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-1*kViewMargin);
        make.top.equalTo(self).offset(50);
        make.height.equalTo(@30);
        make.width.equalTo(@80);
    }];
    
 }


-(void)setDataModel:(BIZConsultorListDataModel *)dataModel {
    _dataModel = dataModel;
    
    [SDWebImageTool imageView:_headImageView imageName:dataModel.headImg placeHolder:@"default-head" showProgress:NO];
    _nameLabel.text = dataModel.cname;
    _positionLabel.text = dataModel.position;
    _companyLabel.text = dataModel.fname;
    
    _levelNameLabel.text = dataModel.levelName;
    
    [self layoutIfNeeded];
    
}

- (void)rechooseBtnClick:(UIButton *)btn {
    !self.rechooseBlock ?:self.rechooseBlock();
}

@end
